import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
# Set up professional academic plotting style
plt.style.use('seaborn-whitegrid')
plt.rcParams.update({
    'font.family': 'serif',
    'font.serif': ['Times New Roman'],
    'mathtext.fontset': 'stix',
    'axes.labelsize': 14,
    'axes.titlesize': 16,
    'xtick.labelsize': 12,
    'ytick.labelsize': 12,
    'legend.fontsize': 12
})

# Simulate experimental data (ε from 1 to 8)
epsilon_values = np.linspace(1, 8, 8)
# FedEntGate accuracy (higher due to selective noise)
fedentgate_acc = [0.75, 0.78, 0.82, 0.84, 0.85, 0.86, 0.865, 0.868]
# DP-FedAvg accuracy (lower due to uniform noise)
dp_fedavg_acc = [0.68, 0.72, 0.75, 0.78, 0.80, 0.81, 0.815, 0.82]
# AdaDP accuracy (adaptive noise baseline)
adadp_acc = [0.70, 0.74, 0.77, 0.80, 0.815, 0.825, 0.83, 0.835]

# Create figure
plt.figure(figsize=(5, 3), dpi=600)

# Plot privacy-utility trade-off curves
plt.plot(epsilon_values, fedentgate_acc, 'o-', color='#1f77b4', 
         linewidth=1, markersize=4, label='FedEntGate')
plt.plot(epsilon_values, adadp_acc, 's--', color='#ff7f0e', 
         linewidth=1, markersize=4, label='AdaDP')
plt.plot(epsilon_values, dp_fedavg_acc, 'D-.', color='#2ca02c', 
         linewidth=1, markersize=4, label='DP-FedAvg')


# Set axis labels and title
plt.xlabel('Privacy Budget (ε)', fontsize=12, fontweight='bold')
plt.ylabel('Accuracy', fontsize=12, fontweight='bold')
# plt.title('Privacy-Utility Trade-off on CIFAR-10 (δ=1e-5)', fontsize=16, pad=15)

# Set axis limits and grid
plt.xlim(1, 8)
plt.ylim(0.65, 0.90)
plt.tick_params(axis='both', which='major', labelsize=10)  # 同时设置x和y轴主刻度
plt.tick_params(axis='both', which='minor', labelsize=6)   # 同时设置x和y轴次刻度

plt.grid(False)

# Add legend
plt.legend(loc='lower right', frameon=True, framealpha=0.9)


# Save high-quality image
plt.tight_layout()
plt.savefig('Fig3_Privacy_Utility_Tradeoff.png', dpi=300, bbox_inches='tight')
plt.show()
